package com.hcf.admin.util;

import java.util.Random;

public class RandomCodeUtil {
    // 定义字符集，包括大写字母、小写字母和数字
    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    // 创建一个随机数生成器
    private static final Random RANDOM = new Random();


    // 生成6位随机gid
    public static String generateRandomGID() {
        return generateRandomCode(6);
    }


    // 生成指定长度的随机字符串
    public static String generateRandomCode(int length) {
        StringBuilder sb = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int randomIndex = RANDOM.nextInt(CHARACTERS.length());
            sb.append(CHARACTERS.charAt(randomIndex));
        }
        return sb.toString();
    }

}
